//
//  LBCDetailListViewController.m
//  Moment
//
//  Created by dllo on 15/11/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LBCDetailListViewController.h"

@interface LBCDetailListViewController ()<UIScrollViewDelegate>

@property (nonatomic, retain)UIScrollView *detailListScrollV;
@property (nonatomic, retain)UIButton *btnHot;
@property (nonatomic, retain)UIButton *btnNew;

@end

@implementation LBCDetailListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = _readListScrollV.name;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"icon_back_h@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(leftButton)];
#pragma mark- 首页scrollView
    _detailListScrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.view addSubview:_detailListScrollV];
    _detailListScrollV.delegate = self;
    _detailListScrollV.contentSize = CGSizeMake(SCREEN_WIDTH * 2, 0);
    _detailListScrollV.showsHorizontalScrollIndicator = YES;
    // 设置按页滑动
    _detailListScrollV.pagingEnabled = YES;
    // 取消边界反弹效果
    _detailListScrollV.bounces = NO;
    _detailListScrollV.contentOffset = CGPointMake(0, 0);
    
    // 最新
    LBCDetailNewViewController *detailNewVC = [LBCDetailNewViewController new];
    detailNewVC.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    detailNewVC.readList = _readListScrollV;
    [_detailListScrollV addSubview:detailNewVC.view];
    
    
    [self addChildViewController:detailNewVC];
    // 最热
    LBCDetailHotViewController *detailHotVC = [LBCDetailHotViewController new];
    detailHotVC.view.frame = CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [_detailListScrollV addSubview:detailHotVC.view];
    detailHotVC.readList = _readListScrollV;
    [self addChildViewController:detailHotVC];

    //最热按钮
//    self.btnHot = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.btnHot.frame = CGRectMake(rightView.width / 8 * 7, rightView.height / 4, rightView.height / 2, rightView.height / 2);
//    [self.btnHot setImage:[UIImage imageNamed:@"iconfont-hot-2.png"] forState:UIControlStateNormal];
//    [self.rightView addSubview:self.btnHot];
//    [self.btnHot addTarget:self action:@selector(hotAction:) forControlEvents:UIControlEventTouchUpInside];
//    
//    //最新按钮
//    self.btnNew = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.btnNew.frame = CGRectMake(rightView.width / 8 * 7 - btnHot.width * 2, rightView.height / 4, rightView.height / 2, rightView.height / 2);
//    [self.btnNew setImage:[UIImage imageNamed:@"iconfont-new-3.png"] forState:UIControlStateNormal];
//    [self.rightView addSubview:self.btnNew];
//    [self.btnNew addTarget:self action:@selector(newAction:) forControlEvents:UIControlEventTouchUpInside];
    

    
}

#pragma mark- 滚动触发
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    self.navigationItem.title = _readListScrollV.name;
}

//减速停止时触发
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (_detailListScrollV.contentOffset.x == SCREEN_WIDTH) {
        [self.btnHot setImage:[UIImage imageNamed:@"iconfont-hot-3.png"] forState:UIControlStateNormal];
        [self.btnNew setImage:[UIImage imageNamed:@"iconfont-new-2.png"] forState:UIControlStateNormal];
    } else if(_detailListScrollV.contentOffset.x == 0) {
        [self.btnNew setImage:[UIImage imageNamed:@"iconfont-new-3.png"] forState:UIControlStateNormal];
        [self.btnHot setImage:[UIImage imageNamed:@"iconfont-hot-2.png"] forState:UIControlStateNormal];
    }
    
}

//- (void)hotAction:(UIButton *)hot{
//    [self.btnHot setImage:[UIImage imageNamed:@"iconfont-hot-3.png"] forState:UIControlStateNormal];
//    [self.btnNew setImage:[UIImage imageNamed:@"iconfont-new-2.png"] forState:UIControlStateNormal];
//    _detailListScrollV.contentOffset = CGPointMake(SCREEN_WIDTH, - 44 - 20);
//}
//
//- (void)newAction:(UIButton *)new{
//    [self.btnNew setImage:[UIImage imageNamed:@"iconfont-new-3.png"] forState:UIControlStateNormal];
//    [self.btnHot setImage:[UIImage imageNamed:@"iconfont-hot-2.png"] forState:UIControlStateNormal];
//    _detailListScrollV.contentOffset = CGPointMake(0, - 44 - 20);
//    
//}

- (void)leftButton{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
